package com.evolution.view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JPanel;

import com.evolution.model.World;

@SuppressWarnings("serial")
public class WorldCanvas extends JPanel{

	private static final int SHAPE_SIZE = 20;
	private World model;
	
	public void setModel(World world){
		this.model = world;
		this.repaint();
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		if(model != null){
			Graphics2D graphics = (Graphics2D)g;
			graphics.setColor(Color.BLACK);
			for(int x = 0;x < model.WORLD_WIDTH;x++){
				for(int y = 0;y < model.WORLD_HEIGHT;y++){
					Rectangle2D shape = new Rectangle2D.Double();
					int shapeX = x * SHAPE_SIZE;
					int shapeY = y * SHAPE_SIZE;
					shape.setRect(shapeX, shapeY, SHAPE_SIZE,SHAPE_SIZE);
					graphics.draw(shape);
					if(model.spaces[x][y].hasFood()){
						RoundRectangle2D shape1 = new RoundRectangle2D.Double(shapeX + 1, shapeY + 1, SHAPE_SIZE,SHAPE_SIZE,20,20);
						//shape1.setRect(shapeX + 1, shapeY + 1, SHAPE_SIZE,SHAPE_SIZE);
						graphics.setColor(Color.GREEN);
						graphics.fill(shape1);
						graphics.setColor(Color.BLACK);
						//graphics.draw(shape);
					}
				}
			}
		}
	}
}
